import { _addComment } from "../../../service/api";

Page({
  data: {
    valueId: null,
    typeId: 1,
    content: "",
  },
  onLoad(options) {
    this.setData({
      valueId: options.valueId,
      typeId: options.typeId,
    });
  },
  handleInpunt(e) {
    this.setData({ content: e.detail.value });
  },
  handleAddComment() {
    const { content, typeId, valueId } = this.data;
    if (!content.trim()) {
      wx.showToast({
        title: "内容不能为空",
        icon: "error",
        duration: 1000,
        mask: true,
      });
    }

    _addComment({ content, typeId, valueId }).then((res) => {
      if (res.errno === 200) {
        wx.showToast({
          title: "评论成功",
          success: (result) => {
            wx.navigateBack({ delta: 1 });
          },
        });
      }
    });
  },
});
